//函数柯里化就是将多参数函数转化成一个参数的函数
function sum(a, b, c) {
  return a + b + c;
}
let sumFn = curry(sum);
function curry(fn, args = []) {
  return function () {
    //下面函数的长度其实就是参数的长度
    let rest = [...args, ...arguments];
    if (rest.length < fn.length) {
      return curry.call(this, fn, rest);
    } else {
      return fn.apply(this, rest);
    }
  }
}
console.log(sumFn(1)(2)(3)); //6
console.log(sumFn(1, 2)(3)); //6